# Contributor: Grigory Kirillov <txgk@bk.ru>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=font-jetbrains-mono
_fontname=${pkgname#font-}
pkgver=2.304
pkgrel=2
pkgdesc="A monospaced typeface made for developers"
url="https://jetbrains.com/mono"
arch="noarch"
license="OFL-1.1"
options="!check" # no test suite
depends="fontconfig mkfontscale"
subpackages="$pkgname-nl $pkgname-vf"
source="https://download.jetbrains.com/fonts/JetBrainsMono-$pkgver.zip
	40-$_fontname.conf
	40-$_fontname-nl.conf
	59-$_fontname-nl.conf
	65-$_fontname.conf
	"
builddir="$srcdir"

package() {
	install -D -m644 fonts/ttf/JetBrainsMono-*.ttf -t "$pkgdir"/usr/share/fonts/$_fontname/

	cd "$pkgdir"
	_install_conf "$srcdir"/40-$_fontname.conf
	_install_conf "$srcdir"/65-$_fontname.conf
}

nl() {
	pkgdesc="$pkgdesc (without coding ligatures)"

	cd "$builddir"
	install -D -m644 fonts/ttf/JetBrainsMonoNL-*.ttf -t "$subpkgdir"/usr/share/fonts/$_fontname/

	cd "$subpkgdir"
	_install_conf "$srcdir"/40-$_fontname-nl.conf
	_install_conf "$srcdir"/59-$_fontname-nl.conf
}

vf() {
	pkgdesc="$pkgdesc (variable font)"

	cd "$builddir"
	install -D -m644 fonts/variable/*.ttf -t "$subpkgdir"/usr/share/fonts/$_fontname/

	cd "$subpkgdir"
	_install_conf "$srcdir"/40-$_fontname.conf 40-$_fontname-vf.conf
	_install_conf "$srcdir"/65-$_fontname.conf 65-$_fontname-vf.conf
}

_install_conf() {
	local src=$1
	local cfgname=${2:-${src##*/}}

	install -D -m644 "$src" usr/share/fontconfig/conf.avail/$cfgname
	mkdir -p etc/fonts/conf.d
	ln -s /usr/share/fontconfig/conf.avail/$cfgname etc/fonts/conf.d/
}

sha512sums="
1889354a5ab1b20a523eccd67686dd6c5aea550a7e9b84d0301b1dac9193c4dde4b6bdac3892bf10603dc0c5f13f2e68363c70c294cc123b91196901f793bdab  JetBrainsMono-2.304.zip
175b458b94aec39202810c0b3354f7647ccc064ea389f1e292dfed8bf6a6e7e23c8ab7dd18e854e9d919d13a82fbc52746688d8892eb40cd38b6414331c55193  40-jetbrains-mono.conf
ffd7000d93ecaeaa37f763a2f80335082151e4d3afc14d19f7c967628bdaa68a03484c09ef299b920d7118793ff30afb262518e79afffc7c5abe122b151b4a32  40-jetbrains-mono-nl.conf
4ec69f863568ef5eb6f494e61999ea74750c47725f40b80a9b5aaa68cef64025aa4e2d3e259a3cd4850b541ec95ad21303d5e07accc84208dfabeaccaf2e9ba7  59-jetbrains-mono-nl.conf
cf5e49b31c09f76b6960c8e980e8020b2ce5136d8ea40559f77a32228a770a2f0ed08ddede908be405ab24773bfb88b9233a478d003dfd1fdcba0209385b8531  65-jetbrains-mono.conf
"
